Latino Rate, Use of Force 2017

Total Rate, by Quadrant, Use of Force 2017
ggplot(data=use_of_force, aes(x = reorder(county_name, total_rate ), y = total_rate , fill = quadrant)) +
geom_bar(stat="identity") +
scale_fill_manual(values=c("green", "orange", "red", "yellow" ), na.value="gray")+
coord_flip() +
labs(title = "Use of Force %",
subtitle = "2017") +
theme_tufte()

MAP
library(leaflet)
library(sf)
library(rgdal)
library(rpostgis)
library(RColorBrewer)
# get counties
shp <- pgGetGeom(con, "cb_2017_us_county_500k", clauses = "where statefp = '06'")
#class(shp)
#spplot(shp, "aland")
dat = merge(shp, use_of_force, by.x="geoid", by.y="county_id", all=TRUE)
spplot(dat, "total_rate")

Interactive map
# define color palette
pal <- colorQuantile(
palette = "YlOrRd",
domain = dat@data$total_rate, n = 5
)
# map
leaflet(dat) %>% # call leaflet library
addProviderTiles(providers$CartoDB.Positron) %>% # call basemap tiles from carto
addPolygons(data=dat, color="gray", # define data and aesthetics to be mapped
weight=1, fillOpacity = 0.7,
fillColor = ~pal(total_rate), # fill color of the polygons, using RColorBrewer palette
# define actions & style for when the user hovers over the polygon
highlightOptions = highlightOptions(
color = "white",
weight = 2,
bringToFront = TRUE),
# define popup text -- concatenate data values with text labels
popup = paste0(dat@data$county_name, " County</br>",
round(dat@data$total_rate, 2),
" Use of Force %")) %>%
# add legend
addLegend(position = "bottomleft",
pal = pal,
values = ~total_rate,
title="Use of Force (%)" )